# -*- coding:utf-8 -*-
# @Author    : g1879
# @date      : 2020-11-17
# @email     : g1879@qq.com
from ListPage import ListPage, Targets, Xpaths

# 定义页面结构
xpaths = Xpaths()
xpaths.pages_count = '//a[@class="icon item"]/preceding-sibling::a[1]'  # 总页数
xpaths.rows = '//div[@class="project-title"]'  # 行
xpaths.set_col('项目', './/h3/a')  # 列1
xpaths.set_col('星数', './/div[@class="stars-count"]')  # 列2

# 定义目标
targets = Targets(xpaths)
targets.add_target('项目', '项目')
targets.add_target('链接', '项目', 'href')
targets.add_target('星数', '星数')

# 列表第一页
url = 'https://gitee.com/explore/weixin-app?page=1'

p = ListPage(xpaths, url)
p.num_param = 'page'

# 从第2页开始爬3页
p.get_list(targets, begin_page=2, count=3)
